package com.igeekhome.shopservice.service.impl;

import com.igeekhome.shop.pojo.TbItemCat;
import com.igeekhome.shopservice.mapper.ItemCatMapper;
import com.igeekhome.shopservice.service.IItemCatService;
import com.igeekhome.shopservice.tree.ItemcatTree;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class ItemCatserviceImpl implements IItemCatService {
    @Resource
    private ItemCatMapper itemCatMapper;
    @Override
    public List<ItemcatTree> list(Long parentId) {
        Example example = new Example(TbItemCat.class);
        Example.Criteria criteria = example.createCriteria();
        Example.Criteria parentId1 = criteria.andEqualTo("parentId", parentId);
        List<TbItemCat> tbItemCats = itemCatMapper.selectByExample(example);
        List<ItemcatTree> list = new ArrayList<>();

        for (TbItemCat tbItemCat : tbItemCats) {
            list.add (new ItemcatTree(tbItemCat.getId(),tbItemCat.getName(),tbItemCat.getIsParent()==1?false:true));

        }

        return list;
    }
}
